package v1

import (
	"github.com/gin-gonic/gin"
	"miomp-terminal-suite/backend/app/common"
)

// GetDashboardOsInfo 获取服务器基础数据
// @Summary Get os info
// @Tags GetDashboardOsInfo
// @Description 获取服务器基础数据
// @Accept json
// @Success 200 {object} dto.OsInfo
// @Security ApiKeyAuth
// @Router /dashboard/os/info [post]
func (b *BaseApi) GetDashboardOsInfo(c *gin.Context) {
	data, err := dashboardService.GetOsInfo()
	if err != nil {
		common.Err.NewBuilder().Error(err).Build(c)
	}
	common.OK.NewBuilder().Data(data).Build(c)
}

// @Tags Dashboard
// @Summary Load dashboard base info
// @Description 获取首页基础数据
// @Accept json
// @Param ioOption path string true "request"
// @Param netOption path string true "request"
// @Success 200 {object} dto.DashboardBase
// @Security ApiKeyAuth
// @Router /dashboard/base/:ioOption/:netOption [post]
func (b *BaseApi) GetDashboardBaseInfo(c *gin.Context) {
	ioOption, ok := c.Params.Get("ioOption")
	if !ok {
		common.Err.NewBuilder().Msg("error netOption in path").Build(c)
		return
	}
	netOption, ok := c.Params.Get("netOption")
	if !ok {
		common.Err.NewBuilder().Msg("error netOption in path").Build(c)
		return
	}
	data, err := dashboardService.GetBaseInfo(ioOption, netOption)
	if err != nil {
		common.Err.NewBuilder().Msg("error netOption in path").Build(c)
		return
	}
	common.OK.NewBuilder().Data(data).Build(c)
}

// @Tags Dashboard
// @Summary Load dashboard current info
// @Description 获取首页实时数据
// @Accept json
// @Param ioOption path string true "request"
// @Param netOption path string true "request"
// @Success 200 {object} dto.DashboardCurrent
// @Security ApiKeyAuth
// @Router /dashboard/current/:ioOption/:netOption [post]
func (b *BaseApi) GetDashboardCurrentInfo(c *gin.Context) {
	ioOption, ok := c.Params.Get("ioOption")
	if !ok {
		common.Err.NewBuilder().Msg("error netOption in path").Build(c)
		return
	}
	netOption, ok := c.Params.Get("netOption")
	if !ok {
		common.Err.NewBuilder().Msg("error netOption in path").Build(c)
		return
	}

	data := dashboardService.GetCurrentInfo(ioOption, netOption)
	common.OK.NewBuilder().Data(data).Build(c)
}
